package com.anpy.bill.controller;

import com.anpy.bill.entity.BankEntity;
import com.anpy.bill.entity.CardEntity;
import com.anpy.bill.entity.PayTypeEntity;
import com.anpy.bill.model.param.DepositParam;
import com.anpy.bill.model.param.SaveBankParam;
import com.anpy.bill.service.CardService;
import com.anpy.common.service.model.result.ApiResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author : anpengyu
 * @create 2024/8/5 13:50
 */
@RestController
@RequestMapping("/card")
@ResponseBody
public class CardController {

    @Resource
    private CardService cardService;

    @PostMapping("/save")
    public ApiResult<String> saveCard(@RequestBody DepositParam depositParam) {
        boolean saveResponse = cardService.saveDeposit(depositParam);
        if (!saveResponse) {
            return ApiResult.failed("卡号已存在");
        }
        return ApiResult.success();
    }

    @GetMapping
    public ApiResult<List<CardEntity>> cardList(Integer depositType, Long userId) {
        List<CardEntity> list = cardService.cardList(depositType,userId);
        return ApiResult.success(list);
    }

    @GetMapping("/payType")
    public ApiResult<List<PayTypeEntity>> payTypeList(Long userId) {
        List<PayTypeEntity> list = cardService.payTypeList(userId);
        return ApiResult.success(list);
    }

    @GetMapping("/bank")
    public ApiResult<List<BankEntity>> bankList(Long userId,Integer type) {
        List<BankEntity> list = cardService.bankList(userId,type);
        return ApiResult.success(list);
    }

    @PostMapping("/bank")
    public ApiResult<Boolean> saveBank(@RequestBody SaveBankParam saveBankParam) {
        int result = cardService.saveBank(saveBankParam);
        if(result == 1){
            return ApiResult.success();
        }
        return ApiResult.failed("添加失败");
    }

}
